/**
 * Created by zhu on 2016/2/11.
 */
$(function () {
    turnover(0, 'dayChange');
    turnover(1, 'monthChange');
    turnover(2, 'yearChange');


});

function turnover(type, id) {

    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById(id));

    // 指定图表的配置项和数据
    var option = {
        title: {
            text: '销售额'

        },
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: ['销售额']
        },
        toolbox: {
            show: true,
            feature: {
                dataZoom: {},
                dataView: {readOnly: false},
                magicType: {type: ['line', 'bar']},
                restore: {},
                saveAsImage: {}
            }
        },
        dataZoom: [
            {
                type: 'slider',
                start: 90,
                end: 100
            },

            {
                type: 'inside',
                start: 10,
                end: 60
            }
        ],
        xAxis: [
            {
                type: 'category',
                boundaryGap: false,
                data: []
            }
        ],
        yAxis: [
            {
                type: 'value',
                axisLabel: {
                    formatter: '{value} ￥'
                }
            }
        ],
        series: {
            name: '销售额',
            type: 'line',
            data: [11, 11, 15, 13, 12, 13, 10],
            markPoint: {
                data: [
                    {type: 'max', name: '最大值'},
                    {type: 'min', name: '最小值'}
                ]
            },
            markLine: {
                data: [
                    {type: 'average', name: '平均值'}
                ]
            }
        }
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
    myChart.showLoading();

    $.get(contextPath + "/mmt_admin/report/turnover/" + type, function (data) {
        data = $.parseJSON(data);
        var x = new Array();
        var y = new Array();
        $.each(data.list, function (i, item) {
            x[i] = item.data;
            y[i] = item.value;
        });
        myChart.hideLoading();
        myChart.setOption(({
            xAxis: [
                {
                    type: 'category',
                    boundaryGap: false,
                    data: x
                }
            ],
            series: {
                data: y
            }
        }));
    })

}

